# -*- coding: utf-8 -*-
import tensorflow as tf

# 创建一个常量
hello = tf.constant("Hello, TensorFlow!")

# 变量 Tensor
var = tf.Variable(6)
print(var)

# 常量 Tensor
m1 = tf.constant([ [1, 2], [3, 4]])
m2 = tf.constant([ [-1, 2], [2, 3]])

multiple = tf.matmul(m1, m2)

sess = tf.Session()

print(sess.run(hello))

# 用Session的run方法来实际运行multiple这个矩阵乘法操作
# 并把操作执行的结果赋值给 result
result = sess.run(multiple)

# 用print打印矩阵乘法的结果
print(result)

if m1.graph is tf.get_default_graph():
    print("m1所在的图（Graph）是当前上下文默认的图")

sess.close()

# 第二种方法来创建和关闭Session
with tf.Session() as sess:
    result2 = sess.run(multiple)
    print("Multiple的结果是 \r\n {}".format(result2))